<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <select id="scsss" onchange="sss()">
          <option value="">订单状态</option>
          <option value="0" <c:if test="${ostatus==0}">selected</c:if> >未支付</option>
          <option value="1" <c:if test="${ostatus==1}">selected</c:if> >已支付</option>
          <option value="2" <c:if test="${ostatus==2}">selected</c:if> >已发货</option>
          <option value="3" <c:if test="${ostatus==3}">selected</c:if> >已收货</option>
          <option value="4" <c:if test="${ostatus==4}">selected</c:if> >已退货</option>
          <option value="5" <c:if test="${ostatus==5}">selected</c:if> >已失效</option>
        </select>
        <form class="layui-form layui-col-md12 x-so" action="orderList" method="post">
<%--          <input class="layui-input" placeholder="开始日" name="start" id="start">--%>
<%--          <input class="layui-input" placeholder="截止日" name="end" id="end">--%>
          <input type="hidden" name="ostatus" value="${ostatus}" />
          <input type="hidden" name="pageNum" value="1" />
          <input type="hidden" name="pageSize" value="5" />
          <input type="text" name="oid" value="${oid}"  placeholder="请输入订单号" autocomplete="off" class="layui-input">
          <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
      </div>
      <xblock>
        <c:if test="${fn:contains(auths,'delOrder')}">
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        </c:if>
          <span class="x-right" style="line-height:40px">共有数据：${pageInfo.total} 条</span>
      </xblock>
      <table class="layui-table">
        <thead>
          <tr>
            <th>
              <input type="checkbox" name="ckAll" >
<%--              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>--%>
            </th>
            <th>订单编号</th>
            <th>收货人</th>
            <th>应付金额</th>
            <th>订单状态</th>
            <th>支付方式</th>
            <th>配送方式</th>
            <th>下单时间</th>
            <th >操作</th>
            </tr>
        </thead>
        <tbody>
          <c:forEach items="${pageInfo.list}" var="order">
            <tr>
              <td>
                <input type="checkbox" name="ck" value="${order.oid}" >
<%--                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>--%>
              </td>
              <td><a href="javascript:void(0)" onclick="x_admin_show('编辑','orderDetailList?oid=${order.oid}')">${order.oid}</a></td>
              <td>${order.address.name} : ${order.address.phone}</td>
              <td>${order.ocountPrice}</td>
              <td><c:if test="${order.ostatus==0}">未支付</c:if><c:if test="${order.ostatus==1}">已支付</c:if>
                <c:if test="${order.ostatus==2}">已发货</c:if><c:if test="${order.ostatus==3}">已签收</c:if>
                <c:if test="${order.ostatus==4}">退货</c:if><c:if test="${order.ostatus==5}">已失效</c:if></td>
              <td>其他方式</td>
              <td>申通物流</td>
              <td>${order.ocreateDate}</td>
              <td class="td-manage">
                <c:if test="${fn:contains(auths,'orderEdit')}">
                  <a title="编辑"  onclick="x_admin_show('编辑','orderEdit?oid=${order.oid}')" href="javascript:;">
                    <i class="layui-icon">&#xe63c;</i>
                  </a>
                </c:if>
                <c:if test="${fn:contains(auths,'delOrder')}">
                  <a title="删除" onclick="member_del(this,'${order.oid}')" href="javascript:;">
                    <i class="layui-icon">&#xe640;</i>
                  </a>
                </c:if>
              </td>
            </tr>
          </c:forEach>
        </tbody>
      </table>
      <div class="page">
        <div>
          <a class="prev"  href="javascript:void(0)" <c:if test="${pageInfo.pageNum>1}"> onclick="ss(${pageInfo.prePage},${pageInfo.pageSize})"</c:if> >&lt;&lt;</a>
          <c:forEach items="${pageInfo.navigatepageNums}" var="i">
            <c:if test="${pageInfo.pageNum==i}">
              <span class="current">${i}</span>
            </c:if>
            <c:if test="${pageInfo.pageNum!=i}">
              <a class="num" onclick="ss(${i},${pageInfo.pageSize})" href="javascript:void(0)">${i}</a>
            </c:if>
          </c:forEach>
          <a class="next" href="javascript:void(0)" <c:if test="${pageInfo.pageNum<pageInfo.pages}"> onclick="ss(${pageInfo.nextPage},${pageInfo.pageSize})"</c:if>>&gt;&gt;</a>
        </div>
      </div>

    </div>
    <script>
      layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });

      function ss(pageNum,pageSize){
        $(":input[name='pageNum']").val(pageNum)
        $(":input[name='pageSize']").val(pageSize)
        $("form").submit();
      }

      $("input[name='ckAll']").click(function () {
        $("input[name='ck']").prop("checked",$("input[name='ckAll']").prop("checked"))
      })
      $("input[name='ck']").click(function () {
        var ss = $("input[name='ck']").length==$("input[name='ck']:checked").length;
        $("input[name='ckAll']").prop("checked",ss)
      })

      function sss() {
          var s = $("#scsss").val();
          console.info(s)
          if(s==""){
              $("input[name='ostatus']").val("-1")
          }else{
              $("input[name='ostatus']").val(s)
          }
      }

      /*用户-删除*/
      function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
          //发异步删除数据
          $.ajax({
            url:"delOrder",
            data:{"oid":id},
            type:"post",
            success:function (result) {
              console.info(result)
              if(result.result=="0000"){
                $(obj).parents("tr").remove();
                layer.msg('已删除!',{icon:1,time:1000});
                $("form").submit();
              }else{
                layer.msg(result.resultMsg,{icon:2,time:1000});
              }
            },
            error:function (result) {
              layer.msg('权限不够!',{icon:2,time:1000});
            },
            dataType:"json"
          })
        });
      }

      function delAll (argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？'+data,function(index){
          //捉到所有被选中的，发异步进行删除
          cks = $("input[name='ck']:checked");
          var str = "";
          for (var i = 0; i < cks.length;i++){
            if(i==cks.length-1){
              str+=cks.eq(i).val();
            }else{
              str+=cks.eq(i).val()+",";
            }
          }
          $.ajax({
            url:"delOrder",
            data:{"oid":str},
            type:"post",
            success:function (result) {
              if(result.result=="0000"){
                layer.msg('删除成功', {icon: 1});
                $("form").submit();
              }else{
                layer.msg(result.resultMsg,{icon:1,time:1000});
              }
            },
            dataType:"json"
          })
        });
      }
    </script>
  </body>

</html>